package com.jml.session;

import com.jml.proxy.MapperProxyFactory;
import java.util.HashMap;
import java.util.Map;


public class Configuration {
    /**
     * 数据源配置
     */
    private DataSource dataSource;

    /**
     * mapper配置扫包访问
     */
    private String mappers;
    /**
     * 注册好的mapper接口
     */
    private final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<Class<?>, MapperProxyFactory<?>>();

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public void setMappers(String mappers) {
        this.mappers = mappers;
    }

    public <T> void addMapper(Class<T> type) {
        knownMappers.put(type, new MapperProxyFactory(type));
    }

    public <T> T getMapper(Class<T> type) {
        MapperProxyFactory<?> mapperProxyFactory = knownMappers.get(type);
        return (T) mapperProxyFactory;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

}
